View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.geronimo.ews.ws4j2ee.toWs.handlers;
18  
19  import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
20  import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFHandler;
21  import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFSOAPHeader;
22  import org.apache.geronimo.ews.ws4j2ee.toWs.AbstractWriter;
23  import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
24  import org.apache.geronimo.ews.ws4j2ee.utils.Utils;
25  
26  /***
27   * <p>Simpley print the Handler without much mess.</p>
28   *
29   * @author Srinath perera(hemapani@opensource.lk)
30   */
31  public class HandlerWriter extends AbstractWriter {
32      private WSCFHandler handler;
33      private String className = null;
34      privateong> String packageName = null;
35  
36      /***
37       * @param j2eewscontext
38       * @throws GenerationFault
39       */
40      public HandlerWriter(J2EEWebServiceContext j2eewscontext, WSCFHandler handler)
41              throws GenerationFault {
42          super(j2eewscontext, j2eewscontext.getMiscInfo().getOutPutPath()
43                  + "/" + handler.getHandlerClass().replace('.', '/') + ".java");
44          this.handler = handler;
45          className = Utils.getClassNameFromQuallifiedName(handler.getHandlerClass());
46          packageName = Utils.getPackageNameFromQuallifiedName(handler.getHandlerClass());
47      }
48  
49      public String getFileName() {
50          throw new UnsupportedOperationException();
51      }
52  
53      /***
54       * just print it out
55       */
56      public void writeCode() throws GenerationFault {
57          if (out == null)
58              return;
59          out.write("package " + packageName + ";\n");
60          out.write("import org.apache.axis.AxisFault;\n");
61          out.write("import org.apache.axis.MessageContext;\n");
62          out.write("public class " + className + " extends org.apache.axis.handlers.BasicHandler{\n");
63          out.write("\tpublic " + className + "(){\n");
64          out.write("\t\tsetName(\"" + handler.getHandlerName() + "\");\n");
65          out.write("\t}\n");
66          out.write("\tpublic void init(){}\n");
67          out.write("\tpublic void cleanup(){}\n");
68          out.write("\tpublic void onFault(MessageContext msgContext){}\n");
69          out.write("\tpublic void invoke(MessageContext msgContext) throws AxisFault{\n");
70          out.write("\t\t//write your implementation here\n");
71          out.write("\t}\n");
72          out.write("\tpublic java.util.List getUnderstoodHeaders() {\n");
73          out.write("\t\t	java.util.List list = new java.util.ArrayList();\n");
74          WSCFSOAPHeader[] headers = handler.getSoapHeader();
75          for (int i = 0; i < headers.length; i++) {
76              out.write("\t\tjavax.xml.namespace.QName name" + i + " = new javax.xml.namespace.QName(\"" + headers[i].getNamespaceURI() + "\",\"" + headers[i].getNamespaceURI() + "\");\n");
77              out.write("\t\tlist.add(name" + i + ");\n");
78          }
79          out.write("\t\treturn list;\n");
80          out.write("\t}\n");
81          out.write("}");
82      }
83  }